    package cn.com.connected.common.config;

import com.baomidou.mybatisplus.extension.handlers.AbstractJsonTypeHandler;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.type.MappedTypes;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

@MappedTypes({List.class})
public class ListIntegerTypeHandler extends AbstractJsonTypeHandler<List<Integer>> {
    @Override
    protected List<Integer> parse(String content) {
        List<Integer> resutls = StringUtils.isEmpty(content) ? Collections.emptyList(): Arrays.stream(content.split(",")).map(Integer::parseInt).collect(Collectors.toList());
        return resutls;
    }

    @Override
    protected String toJson(List<Integer> obj) {
        if (obj==null){
            return null;
        }
        String str = obj.stream().filter(o->o!=null).map(o->o.toString()).collect(Collectors.joining(","));
        return obj==null?null:str;
    }
}